#ifndef TEXT_FILE_READER_H
#define TEXT_FILE_READER_H

#include "./MyTextFileReaderAndWriterNamespace.h"

#include <string>
#include <vector>
#include <unordered_map>
#include <shared_mutex>
//#include <iostream>
#include <fstream>

MY_TEXT_FILE_READER_AND_WRITER_NAMESPACE_BEGIN
class TextFileReaderAndWriter
{
private:
	static std::unordered_map<std::string, std::shared_mutex> full_file_name_2_mutex;
	static std::shared_mutex global_mutex;
	std::ifstream fin;
	std::ofstream fout;
public:
	TextFileReaderAndWriter() = default;
private:
	std::shared_mutex& getMutexFromFullFileName(const std::string& file_name, const std::string& file_extension = "");
public:
	std::vector<std::string> read(const std::string& file_name, const std::string& file_extension = "", std::ios_base::openmode open_mode = std::ios::in);
	std::string readIntoOneString(const std::string& file_name, const std::string& file_extension = "", std::ios_base::openmode open_mode = std::ios::in);
public:
	bool write(const std::string& text, const std::string& file_name, const std::string& file_extension = "", std::ios_base::openmode open_mode = std::ios::out);
};
MY_TEXT_FILE_READER_AND_WRITER_NAMESPACE_END

#endif // !TEXT_FILE_READER_H
